home *** CD-ROM | disk | FTP | other *** search
/ APDL Eductation Resources / APDL Eductation Resources.iso / programs / graphics / gif2rpc / source / 16bpp_66bi / h / internal < prev   
Encoding:
Text File  |  1995-10-07  |  2.7 KB  |  87 lines

  1. /* internal.h
  2.  * AUTHOR:      Cy Booker, cy@cheepnis.demon.co.uk
  3.  * LICENSE:     FreeWare, Copyright (c) 1995 Cy Booker
  4.  * PURPOSE:     common code
  5.  */
  6.  
  7. #ifndef internal_h
  8. #define internal_h
  9.  
  10.  
  11.  
  12. #include "16bpp_66bit.h"
  13.  
  14. #include "gif2rpc:map16bpp.h"
  15.  
  16.  
  17.  
  18. /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  19.  */
  20.  
  21. /*
  22.  * pre-processor macros so that do not pollute name space of library user
  23.  */
  24.  
  25. #define initialise_scaling_tables       process_gif_16bpp_66bit__initialise_scaling_tables
  26. #define Gscale_8bit_to_22bit            process_gif_16bpp_66bit__Gscale_8bit_to_22bit
  27. #define Gscale_5bit_to_22bit            process_gif_16bpp_66bit__Gscale_5bit_to_22bit
  28.  
  29.  
  30.  
  31. /*
  32.  * SCALE is how we represent full intensity
  33.  * it is large so that we can keep track of low errors (ie when we divide the error by 16)
  34.  * must be able to handle +/-1*0xff*SCALE
  35.  * <could remove this restriction if compute the scale[] and map[] arrays using double arithmetic>
  36.  * anyway, will need to handle 0x1f * SCALE in 32 (unsigned) bits
  37.  *
  38.  * we choose as a power of 2 so that compiler can divide by SCALE just by shifting
  39.  *
  40.  */
  41. #define SCALE   (1 << 22)
  42.  
  43.  
  44.  
  45. #define INPUT \
  46.       t = palette[rove[x]];                             /* source pixel palette entry */\
  47.       r = Gscale_8bit_to_22bit[(t >> 8) & 0xff];        /* scale to internal representation */\
  48.       g = Gscale_8bit_to_22bit[(t >> 16) & 0xff];\
  49.       b = Gscale_8bit_to_22bit[(t >> 24) & 0xff]
  50.  
  51.  
  52.  
  53. #define PROCESS \
  54.       r = MAX(r, 0); r = MIN(r, SCALE);                 /* ensure in range */\
  55.       g = MAX(g, 0); g = MIN(g, SCALE);\
  56.       b = MAX(b, 0); b = MIN(b, SCALE);\
  57.       or = ((bits)(r * 0x1f) + (SCALE / 2)) / (bits)SCALE;            /* scale to output */\
  58.       og = ((bits)(g * 0x1f) + (SCALE / 2)) / (bits)SCALE;\
  59.       ob = ((bits)(b * 0x1f) + (SCALE / 2)) / (bits)SCALE;\
  60.       t = or | (og << 5) | (ob << 10);\
  61.       *(((short *)rove) + x) = t;                       /* write pixel */\
  62.       assert((or >= 0) && (or <= 0x1f));\
  63.       assert((og >= 0) && (og <= 0x1f));\
  64.       assert((ob >= 0) && (ob <= 0x1f));\
  65.       or = Gscale_5bit_to_22bit[or];                    /* calculate actual colour output */\
  66.       og = Gscale_5bit_to_22bit[og];\
  67.       ob = Gscale_5bit_to_22bit[ob]
  68.  
  69.  
  70. /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  71.  */
  72.  
  73. extern int              Gscale_8bit_to_22bit[256];    /* 0..0xff -> n*SCALE/0xff */
  74. extern int              Gscale_5bit_to_22bit[32];     /* 0..0x1f -> n*SCALE/0x1f */
  75.  
  76.  
  77.  
  78. /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  79.  * this will initialise the tables once only
  80.  */
  81.  
  82. extern void initialise_scaling_tables(void);
  83.  
  84.  
  85.  
  86. #endif /* internal_h */
  87.